
<template src='./tpl.html'></template>

<script>
import { CONSENT_SORT_TEMPLATE, CONSENT_UNPUBLISH_TEMPLATE, CONSENT_GET_TEMPLATE_LIST, CONSENT_DELETE_TEMPLATE, CONSENT_PUBLISH_TEMPLATE, CONSENT_GET_ZK_LIST } from "_SERVICES/api";
import { trimAll } from "UTILS/string";
import { isvalidateNum2 } from "UTILS/validate";
import { timeFormatter } from "UTILS/format";
import { getStorage, setStorage } from "UTILS/util";
import page from "@/modules/CST/mxins/page";
export default {
  name: "templateList",
  mixins: [page],
  data() {
    return {
      formInline: {
        TPL_MC: "",
        ZTBZ: '',
        filter_zkid: ""
      },

      headers: [
        {
          label: "ID",
          prop: "TID",
          width: 70
        },
        {
          label: "同意书名称",
          prop: "MC",
        }, {
          label: "归属科室",
          prop: "ZKMC",
        }, {
          label: "新增人员",
          prop: "XZYHXM",
        }, {
          label: "修改人员",
          prop: "XGYHXM",
        }, {
          label: "修改时间",
          prop: "XGSJ",
        }

      ],
      ZK_LIST: [],
      permission: false,
      pxVisible: false,
      pxObj: {

      },



    };
  },
  beforeDestroy() {
    setStorage({
      name: "templateList_params",
      value: JSON.stringify(this.formInline)
    })
  },
  created() {
    this.get_zkid_list()


    let userInfo = getStorage("cst_userInfo");
    if (userInfo) {
      userInfo = JSON.parse(userInfo);
    } else {
      userInfo = {}
    }



    //管理员才能删除，编辑，复制模板
    if (userInfo.ROLE_ID && userInfo.ROLE_ID.includes("1")) {
      this.permission = true
    } else {
      this.permission = false

    }

    if (getStorage("templateList_params")) {
      this.formInline = JSON.parse(getStorage("templateList_params"))
    }

    this.getList();




  },
  mounted() { },
  methods: {
    get_zkid_list() {
      CONSENT_GET_ZK_LIST({

      }).then((res) => {
        console.log("获取专科列表成功")
        this.ZK_LIST = res.data || []
      })
    },
    getList(type) {


      this.listLoading = true;
      let params = {
        ...this.formInline,
      };
      if (type != 1) {
        Object.assign(params, this.getParams());
      }

      if (this.permission == false) {
        delete params.filter_zkid
      }

      return CONSENT_GET_TEMPLATE_LIST(params)
        .then((res) => {
          this.listLoading = false;
          this.listQuery.totalNum = res.totalNum;
          if (type == 1) {
            return res.data;
          } else {
            this.tableData = res.data;
          }
          this.CONSENT_GET_CURRENT_VERSION();//检查版本
        })
        .catch((res) => {
          this.listLoading = false;
          this.downloadLoading = false;
      });
    },
    deleteRow(row) {
      this.$confirm('确定要删除此模板吗, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        CONSENT_DELETE_TEMPLATE({
          TID: row.TID
        }).then((res) => {
          this.$message.success("删除成功");
          this.getList()
        })
      }).catch(() => {

      });


    },
    publish(row) {
      this.$confirm('发布之后模板将无法修改, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        CONSENT_PUBLISH_TEMPLATE({
          TID: row.TID
        }).then((res) => {
          this.$message.success("发布成功");
          this.getList()

        }).catch((e) => {
          this.listLoading = false;
        })
      }).catch(() => {

      });
    },
    copyItem(row) {
      this.$router.push({
        path: '/setTemplate',
        query: {
          TID: row.TID,
          TYPE: 1
        }

      })
    },
    eidtZtbz(row) {

      this.$confirm('确定将该模板改为草稿吗, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        CONSENT_UNPUBLISH_TEMPLATE({
          TID: row.TID
        }).then((res) => {
          this.$message.success("修改成功");
          this.getList()

        }).catch((e) => {
          this.listLoading = false;
        })
      }).catch(() => {

      });





    },

    editPx(row) {
      this.pxObj = row;
      this.pxVisible = true
    },
    savePx() {

      CONSENT_SORT_TEMPLATE({
        TID: this.pxObj.TID,
        PX: this.pxObj.PX
      }).then((res) => {
        this.$message.success("修改成功");
        this.pxVisible = false;
        this.getList();
      })

    },
    editRow(row) {
      this.$router.push({
        path: '/setTemplate',
        query: {
          TID: row.TID,
          TYPE: 2
        }

      })
    },
    see(row) {
      this.$router.push({
        path: '/consentTemplate',
        query: {
          TID: row.TID,
          TYPE: 4
        }

      })
    }
  },

};
</script>

<style lang="less"></style>
